package com.tree.common.config.i18n;

import com.tree.common.config.i18n.util.I18nResourceBundleMessageSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.context.MessageSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

/**
 * @ClassName com.demo.common.config.i18n
 * Description: <类功能描述>. <br>
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 2019-05-24 23:29
 * @Version 1.0
 */
@Configuration
@EnableConfigurationProperties({I18nProperties.class})
public class I18nConfig {


    @Bean(name="localMessage")
    public ReloadableResourceBundleMessageSource messageSource(I18nProperties i18nProperties){
        ReloadableResourceBundleMessageSource messageSource = new I18nResourceBundleMessageSource();
        messageSource.setBasename(i18nProperties.getBasename());
        messageSource.setFallbackToSystemLocale(false);
        messageSource.setDefaultEncoding(i18nProperties.getEncoding());
        messageSource.setCacheSeconds(i18nProperties.getCacheDuration());
        messageSource.setUseCodeAsDefaultMessage(true);
        return messageSource;
    }
}
